<template>
	<view class="tab-bar">
		<view class="content">
			<view class="center">
				<image src="/static/images/footer-icon2.png" mode="" @click="switchTab(1)"></image>
			</view>	
			<view class="beside">
				<view class="nav">
					<view class="pic">
						<image v-if="navActive == 0" src="/static/images/footer-icon1.png"></image>
						<image v-else src="/static/images/footer-icon1-1.png" @click="switchTab(0)"></image>
					</view>
					<view class="text" :class="navActive==0? 'active':''" @click="switchTab(0)">
						首页
					</view>
				</view>
				<view class="nav">
					<view class="pic">
						<image v-if="navActive == 2" src="/static/images/footer-icon3-3.png"></image>
						<image v-else src="/static/images/footer-icon3.png" @click="switchTab(2)"></image>
					</view>
					<view class="text" :class="navActive==2? 'active':''" @click="switchTab(2)">
						我的
					</view>
				</view>
			</view>
		</view>
		<!-- 仅负责占位 -->
		<view class="placeholder"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navActive: 0
			};
		},
		mounted() {
			this.initTab();
		},
		methods: {
			initTab(){
				const pages = getCurrentPages(); // 获取当前页面栈
				const currentPage = pages[pages.length - 1]; // 获取当前页面对象
				const currentRoute = currentPage.route; // 获取当前页面路由
				if( currentRoute == 'pages/index/index')this.navActive = 0;
				if( currentRoute == 'pages/Rescue/Rescue')this.navActive = 1;
				if(currentRoute == 'pages/My/My')this.navActive = 2;
			},
			switchTab(i) {
				const pages = getCurrentPages(); // 获取当前页面栈
				const currentPage = pages[pages.length - 1]; // 获取当前页面对象
				const currentRoute = currentPage.route; // 获取当前页面路由
				if (i == 0) {
					if(currentRoute == 'pages/index/index')return;
					uni.switchTab({
						url: '/pages/index/index'
					})
				} else if (i == 1) {
					if(currentRoute == 'pages/Rescue/Rescue')return;
					uni.switchTab({
						url: '/pages/Rescue/Rescue'
					})
				} else {
					if(currentRoute == 'pages/My/My')return;
					uni.switchTab({
						url: '/pages/My/My'
					})
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.tab-bar {
		.content {
			box-shadow: 0px 2px 20px rgba(0, 0, 0, 0.2);
			width: 750rpx;
			height: 15.33vw;
			background-image: url(/static/images/footer-bg.png);
			background-size: cover;
			position: fixed;
			z-index: 999999;
			bottom: -2px;
			left: 0;
		}

		.placeholder {
			height: 15.33vw;
		}

		.center {
			width: 115rpx;
			height: 115rpx;
			position: absolute;
			background: linear-gradient(to right bottom, #ffa24a, #ff4909);
			border-radius: 50%;
			top: -38%;
			left: 50%;
			transform: translateX(-50%);
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				width: 40%;
				height: 40%;
			}
		}

		.beside {
			display: flex;
			height: 15.33vw;

			.nav {
				flex: 1;
				display: flex;
				justify-content: center;
				flex-direction: column;
				align-items: center;

				.pic {
					width: 40rpx;
					height: 40rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.active {
					color: #166BEC;
				}
			}
		}
	}
</style>